home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 754 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  761 b 

  1. From: Drooge@msn.com (Gregory Block)
  2. Subject: RE: ?? pointer to function in C++
  3. Date: 6 Jan 96 21:22:43 -0800
  4. References: <4c2pm4$69d@enterprise.sct.gu.edu.au>
  5. Message-ID: <00001a81+0000893b@msn.com>
  6. Path: news.msn.com!msn.com
  7. Newsgroups: comp.lang.c++
  8. Organization: The Microsoft Network (msn.com)
  9.  
  10. You can take a pointer to a class method in C++, but the compiler 
  11. enforces that the method be bound to a class object. I use the IBM 
  12. CSet++ compiler (OS/2) and can compile the following:
  13.  
  14. class MyClass
  15. {
  16.   typedef void (MyClass::*pfnFunc)();
  17.  
  18.   void whatever_1();
  19.   void whatever_2();
  20.  
  21. };
  22.  
  23. MyClass::whatever_1()
  24. {
  25.   pfnFunc func = whatever_2;
  26.   (this->func)();                // calls whatever_2
  27. }
  28.  
  29. But I'm typing this from memory, so I'm sure you'll find some typos...
  30.  
  31.